#pragma once

#ifdef  __cplusplus
extern "C" {
#endif 

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#ifdef  __cplusplus
};
#endif

#pragma comment(lib,"lua5.1.lib")
#pragma comment(lib,"lua51.lib")

#define EQUAL(D,S)D=S

#define Getter(Parent,Field) Get_##Parent##_##Field
#define Setter(Parent,Field) Set_##Parent##_##Field

#define StartStruct()
#define EndStruct()

#define FieldGetter(Parent,Field,Type)\
	int Getter(Parent,Field)(lua_State *L){\
	Parent *p=(Parent *)lua_touserdata(L,1);\
	if(p){\
	Push_##Type(L,p->Field);\
	return 1;\
	}\
	return 0;\
}

#define FieldSetter(Parent,Field,Type)\
	int Setter(Parent,Field)(lua_State *L){\
	Parent *p=(Parent *)lua_touserdata(L,1);\
	if(p){\
	Set_##Type(p->Field,Get_##Type(L,2));\
	}\
	return 0;\
}

#define SGField(Parent,Field,Type)\
	FieldGetter(Parent,Field,Type)\
	FieldSetter(Parent,Field,Type)